package com.zx.model;

import java.util.ArrayList;
import java.util.List;

public class ConfContent implements Cloneable {
	private String 				confName;
	private String 				confValue;
	private List<ConfContent> 	childContent;

	public String getConfName() {
		return confName;
	}

	public void setConfName(String confName) {
		this.confName = confName;
	}

	public String getConfValue() {
		return confValue;
	}

	public void setConfValue(String confValue) {
		this.confValue = confValue;
	}

	public List<ConfContent> getChildContent() {
		return childContent;
	}

	public void setChildContent(List<ConfContent> childContent) {
		this.childContent = childContent;
	}

	@Override
	public String toString() {
		String str = "[" + confName + "] [" + (confValue == null ? "" : confValue) + "]";
		if(this.childContent != null) {
			str +=  " {\r\n";
			for (ConfContent confContent : childContent) {
				String s = confContent.toString();
				String[] split = s.split("\r\n");
				for (String string : split) {
					str += "\t" + string + "\r\n";
				}
			}
			str += "}\r\n";
		} else {
			str += ";\r\n";
		}
		return str;
	}
	
	
	@Override
	public Object clone() throws CloneNotSupportedException {
		ConfContent clone = (ConfContent)super.clone();
		if(clone.getChildContent() != null && !clone.getChildContent().isEmpty()) {
			List<ConfContent> li = new ArrayList<>();
			for (ConfContent childContent : clone.getChildContent()) {
				li.add((ConfContent)childContent.clone());
			}
			clone.setChildContent(li);
		} 
		return clone;
	}
}
